It is often desirable to change a code execution path in a running process without changing the original on-disk image of the executing modules or without requiring a restart of the computer. One way to accomplish this is via a “Hotpatching” mechanism. Hotpatching is in-memory patching mechanism that enables the installation of software updates without requiring users to restart their computers by automatically inserting code from a software update into a running process. This means that system files can be updated while they are in use.
For example, Hotpatching may bypass a vulnerable function in a running process by injecting a JMP instruction at the beginning of the vulnerable function. When the function is called, it jumps to a new function that is also loaded into the process space by the Hotpatching mechanism. The problem with this approach is that an injected JMP instruction may overwrite multiple instructions in a way that leads to unexpected behavior. In the Hotpatching case, if the beginning of the vulnerable function includes 3 assembly opcodes in the first 5 bytes (1 byte opcode, 2 bytes opcode, 2 bytes opcode), the JMP injection will replace all five bytes. If the processor is executing the first byte opcode, and the injection has changed the next two opcodes, unexpected processor behavior may result.